package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.XaWuziMapper;
import com.ruoyi.system.domain.XaWuzi;
import com.ruoyi.system.service.IXaWuziService;
import com.ruoyi.common.core.text.Convert;

/**
 * 物资Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-11-08
 */
@Service
public class XaWuziServiceImpl implements IXaWuziService 
{
    @Autowired
    private XaWuziMapper xaWuziMapper;

    /**
     * 查询物资
     * 
     * @param id 物资ID
     * @return 物资
     */
    @Override
    public XaWuzi selectXaWuziById(Long id)
    {
        return xaWuziMapper.selectXaWuziById(id);
    }

    /**
     * 查询物资列表
     * 
     * @param xaWuzi 物资
     * @return 物资
     */
    @Override
    public List<XaWuzi> selectXaWuziList(XaWuzi xaWuzi)
    {
        return xaWuziMapper.selectXaWuziList(xaWuzi);
    }

    /**
     * 新增物资
     * 
     * @param xaWuzi 物资
     * @return 结果
     */
    @Override
    public int insertXaWuzi(XaWuzi xaWuzi)
    {
        return xaWuziMapper.insertXaWuzi(xaWuzi);
    }

    /**
     * 修改物资
     * 
     * @param xaWuzi 物资
     * @return 结果
     */
    @Override
    public int updateXaWuzi(XaWuzi xaWuzi)
    {
        return xaWuziMapper.updateXaWuzi(xaWuzi);
    }

    /**
     * 删除物资对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteXaWuziByIds(String ids)
    {
        return xaWuziMapper.deleteXaWuziByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除物资信息
     * 
     * @param id 物资ID
     * @return 结果
     */
    @Override
    public int deleteXaWuziById(Long id)
    {
        return xaWuziMapper.deleteXaWuziById(id);
    }

    /**
     * 查询物资树列表
     * 
     * @return 所有物资信息
     */
    @Override
    public List<Ztree> selectXaWuziTree()
    {
        List<XaWuzi> xaWuziList = xaWuziMapper.selectXaWuziList(new XaWuzi());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (XaWuzi xaWuzi : xaWuziList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(xaWuzi.getDanweiId());
            ztree.setpId(xaWuzi.getDanweiId());
            ztree.setName(xaWuzi.getDanweiId());
            ztree.setTitle(xaWuzi.getDanweiId());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
